﻿
--划客户
CREATE PROCEDURE [dbo].[proc_Customer_Hua]
(
	@TypeId int,
	@CusId uniqueidentifier,
	@CusName nvarchar(50),
	@UserName nvarchar(50),
	@EName nvarchar(50),
	@CreateName nvarchar(50)
)
AS
Begin
	DECLARE	@ProtectId VARCHAR(30)
	DECLARE	@ProtectName NVARCHAR(30)
	DECLARE	@protectDate VARCHAR(30)

If @TypeId = 2 Or @TypeId = 4		
	Begin
		--保存原始记录
		Select @ProtectId=ISNULL(ProtectId,''),@ProtectName=ISNULL(ProtectName,''),@protectDate=ISNULL(Convert(varchar,ProtectDate,120),'') FROM Customer Where CustomerId=@CusId

		--更新客户表
		Update customer Set protectid=@TypeId,ProtectName=@UserName,protectdate=getdate() Where CustomerId=@CusId

		--插入日志表
		Insert Into Customer_HuaTemp(CusId,CusName,UserName,EName,CreateName,CreateDate,CusInfo) Values(@CusId,@CusName,@UserName,@EName,@CreateName,getdate(),'['+@ProtectId+'],['+@ProtectName+'],['+@protectDate+']')

		Select 1
	End
Else
	Select -1
End